package com.share.finance.risk.rules.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.share.common.common.Page;
import com.share.finance.risk.rules.mapper.StrategyConfMapper;
import com.share.finance.risk.rules.model.db.StrategyConf;
import com.share.finance.risk.rules.model.vo.StrategyConfPageReq;
import com.share.finance.risk.rules.service.IStrategyConfService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 策略表  服务实现类
 * </p>
 *
 * @author author
 * @since 2023-12-25
 */
@Service
public class StrategyConfServiceImpl extends ServiceImpl<StrategyConfMapper, StrategyConf> implements IStrategyConfService {
    @Resource
    private StrategyConfMapper strategyMapper;

    @Override
    public Page<StrategyConf> pageList(StrategyConfPageReq req) {
        PageHelper.startPage(req.getPageNum(), req.getPageSize());
        LambdaQueryWrapper<StrategyConf> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StrategyConf::getStatus, 1);
        if (StringUtils.isNotBlank(req.getBody())) {
            queryWrapper.like(StrategyConf::getBody, req.getBody());
        }
        if (StringUtils.isNotBlank(req.getName())) {
            queryWrapper.like(StrategyConf::getName, req.getName());
        }
        if (StringUtils.isNotBlank(req.getVars())) {
            queryWrapper.like(StrategyConf::getVars, req.getVars());
        }
        if (StringUtils.isNotBlank(req.getInts())) {
            queryWrapper.like(StrategyConf::getInts, req.getInts());
        }
        List<StrategyConf> list = strategyMapper.selectList(queryWrapper);
        Page<StrategyConf> page = new Page<>(list, new PageInfo<>(list).getTotal(), req);
        return page;
    }
}
